// pages/my/updateUser/updateUser.js
const app = getApp();
var service = require('../../../util/service');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user:{},
    name: "",
    buyDesc: "",
  },
  formSubmit: function (e) {
    let { name, buyDesc} = e.detail.value;
    if (!name || !buyDesc) {
      wx.showToast({
        title: "请完善信息再保存",
        icon: 'none',
        duration: 1000,
        mask: true
      })
      return;
    }
    var user = this.data.user;
    user.buyName = name;
    user.buyDesc = buyDesc;
    delete user.createdAt;
    delete user.lastedUpdAt;
    delete user.vipEndEffe;
    delete user.lastedUpdBy;
    delete user.createdBy;

    //更新微信用户信息以及平台用户信息
    service.AJAX(`smc/base/SystemBuyerUser/updSystemBuyerUser.do`, user, res => { 
      wx.showToast({
        title: "保存成功",
        duration: 1000,
        mask: true
      })
      app.userInfo = user;
      wx.navigateBack();
      
    }, err => { }, "POST");

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    service.AJAX(`smc/base/SystemBuyerUser/choiceLoginTo.do?openId=${app.globalData.openid}`, {}, res => {
      if (res) {
        this.setData({
          user: res,
          name: res.buyName,
          buyDesc: res.buyDesc
        })
      }
    }, err => { }, "POST")
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})